Build a mental model
for React architecture.
This guide is designed to answer your questions before you ask them.
Click the "Common Confusion" tags to see deep dives.
A Component is just a JavaScript function that returns a UI blueprint (JSX).
export default function Header() {
return <h1>Welcome to React</h1>;
}
import Header from './Header';
function App() {
return (
<div>
<Header />
</div>
);
}
Welcome to React
React.createElement() calls.
It's essentially "Syntactic Sugar" for a bunch of JS objects.
Props allow parent components to share data with children. Destructuring is the professional standard for keeping your code clean.
Why Destructure? It defines the component's "API" at the top level. You see
exactly what data is needed without hunting through the code for
props.something.
function Card(props) {
return <h1>{props.title}</h1>;
}
Passes everything as one object. You must use props. to access any value inside.
function Card({ title }) {
return <h1>{title}</h1>;
}
Unpacks the specific data you need immediately. No more typing props. over and over.
App.jsx (The Sender)
function App() {
return <Profile name="Alex" role="Dev" />;
}
Profile.jsx (The Receiver)
function Profile({ name, role }) {
return (
<div>
<h3>{name}</h3>
<p>{role}</p>
</div>
);
}
User: Alex
Role: Dev
🍽️The Restaurant Analogy
Think of React like a Kitchen: Trigger is the customer placing an order. Render is the chef preparing the food in the kitchen (hidden). Commit is the waiter placing the finished plate on your table (visible).
Trigger
The order is placed. React marks the component as "dirty" and schedules the update.
Render (Math)
The chef calculates the difference. "The old button was red, the new one is blue." No screen change yet.
Commit
The waiter brings the plate. React applies the minimal changes to the real browser DOM.
Still a bit unclear? Don't worry! In the next module when we cover useState(), everything will become crystalclear.
Dynamic Data
In React, we don't manually repeat HTML tags for every piece of data. Instead, we use the .map() method to loop through an array and automatically generate a list of components based on your data.
const fruits = [
{ id: 1, name: "🍎 Apple" },
{ id: 2, name: "🍌 Banana" }
]
function App() {
return (
<ul>
{fruits.map((fruit) => (
<li key={fruit.id} className="fruit-item">
{fruit.name}
</li>
))}
</ul>
)
}
React uses .map() to transform your data array into visual JSX elements.
- 1 🍎 Apple
- 2 🍌 Banana
They "Key" Rule
Always provide a unique key (like an ID) to each list item. This helps React's "diffing" algorithm know exactly which item changed, moved, or was deleted.
Structure & Strict Mode
1. Fragments vs Div Soup
<div> <!-- Extra tag! -->
<h1>Hello World</h1>
</div>
Why it matters: Using extra <div> tags for grouping can break CSS layouts (like Flexbox and Grid) and clutter the browser inspector.
The Solution: Fragments let you group items without adding any real HTML tags to the final page.
3. Class vs ClassName
<div class="container">...</div>
<div className="container">...</div>
Why? "class" is a reserved keyword in JavaScript. React uses className to avoid conflicts.
2. Strict Mode Lifecycle
import React from 'react';
import ReactDOM from 'react-dom/client';
ReactDOM.createRoot(root).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Are you ready for State & Effects?
If you understand that React is just a transformation engine that takes Data (Props) and turns it into Blueprints (JSX) efficiently, you are 90% there.